package com.lbmb.mdps.workbench.service.impl;

import com.lbmb.mdps.commons.domain.MedicineTypeReceive;
import com.lbmb.mdps.commons.domain.MedicineTypeVo;
import com.lbmb.mdps.commons.exception.MedicineTypeException;
import com.lbmb.mdps.workbench.dao.MedicineTypeDao;
import com.lbmb.mdps.workbench.domain.MedicineType;
import com.lbmb.mdps.workbench.service.MedicineTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 林文塨
 * @date 2022-05-30 23:12
 * description
 */
@Service("medicineTypeService")
public class MedicineTypeServiceImpl implements MedicineTypeService {

    @Resource
    private MedicineTypeDao medicineTypeDao;

    @Override
    public List<MedicineType> medicineTypePageList(MedicineTypeReceive medicineTypeReceive) throws MedicineTypeException {
        /*
         * 分页获取药品类别表功能
         * @author 林文塨
         * @date 2022/5/30 10:24
         * @param [employeeReceive]
         * @return java.util.List<com.lbmb.mdps.settings.domain.Employee>
         */
        List<MedicineType> medicineTypeList = medicineTypeDao.medicineTypePageList(medicineTypeReceive);

        if (medicineTypeList == null) {
            throw new MedicineTypeException("分页获取药品类别列表失败！");
        }

        return medicineTypeList;
    }

    @Override
    public Integer getMedicineTypeTotal(MedicineTypeReceive medicineTypeReceive) throws MedicineTypeException {
        /*
         * 获取药品类别分页总条数功能
         * @author 林文塨
         * @date 2022/5/30 10:42
         * @param [employeeReceive]
         * @return java.lang.Integer
         */
        Integer total = medicineTypeDao.getMedicineTypeTotal(medicineTypeReceive);

        if (total < 0) {
            throw new MedicineTypeException("获取药品类别分页总条数失败！");
        }

        return total;
    }

    @Override
    public void addMedicineType(MedicineType medicineType) throws MedicineTypeException {
        /*
         * 添加药品类别
         * @author 林文塨
         * @date 2022/5/30 13:06
         * @param [employee]
         * @return void
         */
        int result = medicineTypeDao.addMedicineType(medicineType);

        if (result != 1) {
            throw new MedicineTypeException("添加药品类别失败！");
        }
    }

    @Override
    public void editMedicineType(MedicineType medicineType) throws MedicineTypeException {
        /*
         * 修改药品类别
         * @author 林文塨
         * @date 2022/5/30 13:06
         * @param [employee]
         * @return void
         */
        int result = medicineTypeDao.editMedicineType(medicineType);

        if (result != 1) {
            throw new MedicineTypeException("修改药品类别失败！");
        }
    }

    @Override
    public void deleteMedicineType(String[] deleteMedicineTypeIds) throws MedicineTypeException {
        /*
         * 删除药品类别
         * @author 林文塨
         * @date 2022/5/30 16:32
         * @param [deleteEmployeeIds]
         * @return void
         */
        int result = medicineTypeDao.deleteMedicineType(deleteMedicineTypeIds);

        if (result <= 0) {
            throw new MedicineTypeException("删除药品类别失败");
        }
    }

    @Override
    public List<MedicineTypeVo> getAllMedicineType() {
        /*
         * 获得全部药品类型
         * @author 林文塨
         * @date 2022/5/31 11:01
         * @param []
         * @return java.util.List<com.lbmb.mdps.commons.domain.MedicineTypeVo>
         */
        List<MedicineType> medicineTypeList = medicineTypeDao.getAllMedicineType();
        List<MedicineTypeVo> medicineTypeVoList = new ArrayList<>();

        for (MedicineType medicineType : medicineTypeList) {
            MedicineTypeVo medicineTypeVo = new MedicineTypeVo();
            medicineTypeVo.setLabel(medicineType.getType());
            medicineTypeVo.setValue(medicineType.getId());

            medicineTypeVoList.add(medicineTypeVo);
        }

        return medicineTypeVoList;
    }
}
